/*
 * Copyright 2010 GP Software
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * BeanMapping.java | Created on Apr 22, 2010
 */
package org.gp.gpetl.config;

import java.util.ArrayList;
import java.util.List;

/**
 * Value object for bean mapping configuration
 *
 * @author Paul Augustine C. Mendoza
 * @since 1.0
 */
public class BeanMapping implements ConfigObject {

    /**
     * The name
     */
    private String name;

    /**
     * The tablename name
     */
    private String tablename;

    /**
     * The mappings
     */
    private List<Mapping> mappings;

    /**
     * The default constructor
     */
    public BeanMapping() {
        this.mappings = new ArrayList<Mapping>();
    }

    /**
     * Gets the name
     *
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * Sets the name
     *
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Gets the tablename name
     *
     * @return the tablename name
     */
    public String getTablename() {
        return tablename;
    }

    /**
     * Sets the tablename name
     *
     * @param tablename the tablename name to set
     */
    public void setTablename(String tablename) {
        this.tablename = tablename;
    }

    /**
     * Gets the mappings
     *
     * @return the mappings
     */
    public List<Mapping> getMappings() {
        return mappings;
    }

    /**
     * Sets the mappings
     *
     * @param mappings the mappings to set
     */
    public void setMappings(List<Mapping> mappings) {
        this.mappings = mappings;
    }

    /**
     * @see Object#toString()
     */
    @Override
    public String toString() {
        return "BeanMapping{" +
                "name='" + name + '\'' +
                ", tablename='" + tablename + '\'' +
                ", mappings size=" + mappings.size() +
                '}';
    }

    /**
     * @see Object#equals(Object)
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        BeanMapping that = (BeanMapping) o;

        if (mappings != null ?
                !mappings.equals(that.mappings) :
                that.mappings != null) return false;
        if (name != null ? !name.equals(that.name) : that.name != null)
            return false;
        if (tablename != null ?
                !tablename.equals(that.tablename) :
                that.tablename != null) return false;

        return true;
    }

    /**
     * @see Object#hashCode()
     */
    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (tablename != null ? tablename.hashCode() : 0);
        result = 31 * result + (mappings != null ? mappings.hashCode() : 0);
        return result;
    }
}
